package com.mi.common.core.jackson;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.util.Objects;

/**
 * String To Long Deserializer
 *
 * @author jin_huaquan
 * @version 1.0
 * @date 2022/1/12 14:11
 */
public class ToLongDeserializer extends JsonDeserializer<Long> {

    @Override
    public Long deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
        if (Objects.isNull(jsonParser)) {
            return null;
        }

        String text = jsonParser.getText();

        return Long.parseLong(text);
    }
}
